package comparator;

public class Employee implements  Comparable{
    public int age;

    public double sarly;

    public String name;

    public Employee(int age, double sarly, String name) {
        this.age = age;
        this.sarly = sarly;
        this.name = name;
    }

    /**
     *
     * @param o 目标对象
     * @return
     */
    @Override
    public int compareTo(Object o) {
        // 1. 将目标对象转换为需要被比较对象
        Employee e = (Employee) o;

        if(this.sarly < e.sarly)
            return -1; // 返回负数表示将当前对象放前面
        else if(this.sarly == e.sarly){
            if(this.age > e.age){
                return -1;
            }else{
                return 1;
            }
        } else
            return 1; // 返回正整数表示将目标对象放前面

        //以上可以简写为： return this.sarly - e.sarly;

    }
}
